package com.xzy.Service;

import com.xzy.dao.StarsDao;
import com.xzy.pojo.Stars;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class StarsServiceImpl implements StarsService{
    @Autowired
    StarsDao starsDao;

    @Override
    public <S extends Stars> S save(S s) {
        return starsDao.save(s);
    }

    @Override
    public Page<Stars> findAll(int page) {
        Pageable pageable= PageRequest.of(page,3, Sort.Direction.ASC,"id");
        return starsDao.findAll(pageable);
    }

    @Override
    public long count() {
        return starsDao.count();
    }

    @Override
    public Optional<Stars> findById(Integer integer) {
        return starsDao.findById(integer);
    }

    @Override
    public int getMaxId() {
        return starsDao.getMaxId();
    }

    @Override
    public void deleteById(Integer integer) {
        starsDao.deleteById(integer);
    }

}
